home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / hips / sources / vfft / pattern.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-02  |  4.9 KB  |  215 lines

  1. /*
  2. %    PATTERN . C
  3. %
  4. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  5.  
  6. This software is copyright (C) by the Lawrence Berkeley Laboratory.
  7. Permission is granted to reproduce this software for non-commercial
  8. purposes provided that this notice is left intact.
  9.  
  10. It is acknowledged that the U.S. Government has rights to this software
  11. under Contract DE-AC03-765F00098 between the U.S.  Department of Energy
  12. and the University of California.
  13.  
  14. This software is provided as a professional and academic contribution
  15. for joint exchange. Thus, it is experimental, and is provided ``as is'',
  16. with no warranties of any kind whatsoever, no support, no promise of
  17. updates, or printed documentation. By using this software, you
  18. acknowledge that the Lawrence Berkeley Laboratory and Regents of the
  19. University of California shall have no liability with respect to the
  20. infringement of other copyrights by any part of this software.
  21.  
  22. For further information about this notice, contact William Johnston,
  23. Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  24. (wejohnston@lbl.gov)
  25.  
  26. For further information about this software, contact:
  27.     Jin Guojun
  28.     Bld. 50B, Rm. 2275, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  29.     g_jin@lbl.gov
  30.  
  31. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  32. %
  33. %    pattern generates the variant square pattern.
  34. */
  35. char    usage[]="options\n\
  36. [-c #]        columns [256]\n\
  37. [-r #]        rows [256]\n\
  38. [-fr #]        frames for repeating output [1]\n\
  39. [-h #]        line height [8]\n\
  40. [-fx #]        function number on X axis\n\
  41. [-fy #]        function number on Y axis\n\
  42. [-p #]        circles of sine function\n\
  43. [-s #]        step of equal difference [2]\n\
  44. [-w #]        line width [8]\n\
  45. [<] input [> output]\n\n\
  46. functions:\n\
  47. 0    square - n, n, n\n\
  48. 1    step - 1,2,3, ...\n\
  49. 2    equal difference - 1, 4, 7, 10, ... {ed=3 => -s 3}\n\
  50. 3    pascal tri-angle\n\
  51. 4    power of 2\n\
  52. 5    sine\n";
  53. /*
  54. % compile:    cc -O -o DEST/pattern pattern.c -lscs1 -lccs -lhips -lm
  55. %
  56. % AUTHOR:    Guojun Jin - LBL    5/1/91
  57. */
  58.  
  59. #include <math.h>
  60. #include "header.def"
  61. #include "imagedef.h"
  62.  
  63. U_IMAGE    uimg;
  64.  
  65. #define    inbuf    uimg.src
  66. #define    obuf    uimg.dest
  67. #define    row    uimg.height
  68. #define    cln    uimg.width
  69. #define    frm    uimg.frames
  70.  
  71. #ifdef    _DEBUG_
  72. extern    int    debug;
  73. #endif
  74. #define    SValue(type)    avset(argc, argv, &l, &f, type)
  75.  
  76. int    line_height=8, line_width=8, illuminance[2]={0, 255}, step_len=2;
  77. bool    Msg;
  78.  
  79.  
  80. main(argc, argv)
  81. int    argc;
  82. char*    argv[];
  83. {
  84. int    l, f, fsize, total, point, bgrd, fx=0, fy=0, circle=1;
  85. byte    *buf, *linebuf, *line0, *line1;
  86.  
  87. format_init(&uimg, IMAGE_INIT_TYPE, HIPS, -1, *argv, "S16-1");
  88.  
  89. uimg.width = uimg.height = 256;
  90. uimg.frames = uimg.pxl_out = 1;
  91. uimg.o_form = IFMT_BYTE;
  92. (*uimg.std_swif)(FI_INIT_NAME, &uimg, *argv, 0);
  93.  
  94. for (l=1; l<argc; l++)
  95.     if (*argv[l] == '-'){
  96.     f=1;
  97.     switch (argv[l][f++]){
  98.     case 'c':
  99.         if (SValue(0))
  100.             cln = atoi(argv[l]+f);
  101.         break;
  102.     case 'f':
  103.     {
  104.     register int    who=argv[l][f++];
  105.         if (SValue(0))
  106.             f = atoi(argv[l]+f);
  107.         switch(who){
  108.         case 'r':
  109.             frm = f;
  110.             break;
  111.         case 'x':
  112.             fx = f;
  113.             break;
  114.         case 'y':
  115.             fy = f;
  116.         }
  117.     }    break;
  118.     case 'h':
  119.         if (SValue(0))
  120.             line_height = atoi(argv[l]+f);
  121.         break;
  122.     case 'p':
  123.         if (SValue(0))
  124.             circle = atoi(argv[l]+f);
  125.         break;
  126.     case 'r':
  127.         if (SValue(0))
  128.             row = atoi(argv[l]+f);
  129.         break;
  130.     case 's':
  131.         if (SValue(0))
  132.             step_len = atoi(argv[l]+f);
  133.         break;
  134.     case 'w':
  135.         if (SValue(0))
  136.             line_width = atoi(argv[l]+f);
  137.         break;
  138.     case 'v':    Msg++;
  139.         break;
  140.     case 'o':if (SValue(1) && freopen(argv[l]+f, "wb", out_fp))    break;
  141.         message("%s can't be opened", argv[l]);
  142.     default:
  143. info:        usage_n_options(usage, l, argv[l]);
  144.     }
  145.     }
  146.     else if (freopen(argv[l], "r", stdin)==NULL)
  147.     syserr("can't open frame file - %s",argv[l]);
  148.  
  149. io_test(stdout_fd, goto info);
  150.  
  151. fsize = row * cln;
  152. buf = nzalloc(row, cln, "buf");
  153. linebuf = nzalloc(2, cln, "linebuf");
  154. line0 = linebuf;
  155. line1 = linebuf + cln;
  156.  
  157. for (total=f=0; total<cln; f++){
  158. register int    samples=function(f, fx, line_width, circle);
  159.  
  160.     total += samples;
  161.     if (total > cln)    samples -= total - cln;
  162.     point = illuminance[f & 1];
  163.     bgrd = illuminance[!(f & 1)];
  164.     do {
  165.         *line0++ = point;
  166.         *line1++ = bgrd;
  167.     } while(--samples);
  168. }
  169. line0 = linebuf;
  170. line1 = linebuf + cln;
  171. {
  172. register byte    *bp = buf, *lp;
  173.     for (total=f=0; total<row; f++){
  174.     register int    lines = function(f, fy, line_height, circle);
  175.  
  176.     total += lines;
  177.     if (total > row)    lines -= total - row;
  178.     lp = (f&1) ? line0 : line1;
  179.     for (l=0; l<lines; l++, bp+=cln)
  180.         memcpy(bp, lp, cln);
  181.     }
  182. }
  183.  
  184. (*uimg.header_handle)(HEADER_WRITE, &uimg, argc, argv, True);
  185.  
  186. for (f=frm; f--;){
  187.     l = fwrite(buf, cln, row, out_fp);
  188.     if (l != row)
  189.         syserr("[%d] write %d", row, l);
  190. }
  191. exit(0);
  192. }
  193.  
  194. function(n, fn, width, period)
  195. register int    n, fn, width;
  196. {
  197. static int    base=1;
  198. register int    v;
  199.  
  200. if (!width)    return    base=1;
  201.  
  202. switch (fn)    {
  203. default:
  204. case 0:    v = 1;    break;
  205. case 1:    v = n*step_len+1;    break;
  206. case 2:    v = n*width + 1;    break;
  207. case 3:    v = base += n;    break;
  208. case 4:    v = 1 << n;    break;
  209. case 5:    v = sin(n*period*M_PI / width) * width;
  210.     if (! v)    v++;
  211.     else if (v<0)    v = -v;
  212. }
  213. return    v * width;
  214. }
  215.